    % Get portfolio by market code, number of stocks, stock codes, and weights
% Input: market_code, number_of_stocks, stock_codes, porfolio_weights
% Output: portfolio_codes, porfolio_weights, portfolio_date, and portfolio_close_price
function [portfolio_codes porfolio_weights portfolio_date portfolio_close_price portfolio_volume] = getPortfolio(market_code, number_of_stocks, stock_codes, porfolio_weights)

    % the minimum of the number of stocks
    MIN_NUMBER_OF_STOCKS = 5;
    % the maximum of the number of stocks
    MAX_NUMBER_OF_STOCKS = 10;

    % if the market is null => random market
    if (isempty(market_code))
        market_code = getRandomMarketCode();
        market_code = cell2mat(market_code);
    end
    
    % if the number of stocks is null => random number of stocks
    if (isempty(number_of_stocks))
        number_of_stocks = randi([MIN_NUMBER_OF_STOCKS, MAX_NUMBER_OF_STOCKS]);
    end
    
    % if vector weight is null => random vector weight
    if (isempty(porfolio_weights))
        porfolio_weights = getRandomWeights(number_of_stocks);
    end
        
    % if the list of stock codes in portfolio is null => random the list of
    % stock codes
    if (isempty(stock_codes))
        stock_codes = getRandomStockCodes(market_code, number_of_stocks, 250, 5000)
        
    end
    
    [portfolio_codes portfolio_date portfolio_close_price portfolio_volume] = getIndex(market_code);
    % load all stocks data and normalize data
    delta_index = 0;
    for stock_codes_index = 1:number_of_stocks
        % load data of a stock
        [code_temp date_temp price_temp volume_temp] = getStock(cell2mat(stock_codes(stock_codes_index + delta_index)));
        portfolio_codes = [portfolio_codes; mat2cell(code_temp)];
        % normalize data
        [portfolio_date portfolio_close_price portfolio_volume] = getIntersectOfStockTable(stock_codes_index, portfolio_date, portfolio_close_price, portfolio_volume, date_temp, price_temp, volume_temp);
    end
    if (length(portfolio_volume)<=250)
        [portfolio_codes porfolio_weights portfolio_date portfolio_close_price portfolio_volume] = getPortfolio(market_code, [], [], [])
    end
end